package com.tn.controller.map;

import com.tn.controller.alarm.common.model.CommonVO;
import com.tn.controller.alarm.common.model.camera.vo.CameraVO;
import com.tn.controller.alarm.common.model.map.TruckInfoVO;
import com.tn.controller.alarm.common.model.map.TruckTrailVO;
import com.tn.controller.alarm.common.model.map.VehicleInfoVO;
import com.tn.exception.DatabaseOperationFailedException;
import com.tn.exception.InvalidParamException;
import com.tn.service.camera.ICameraService;
import com.tn.service.map.IMapService;
import com.tn.utils.CheckParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 地图Controller
 *
 * @program: tn_aucy_java
 * @author: yangjiayao
 * @create: 2022/1/4
 */
@Slf4j
@RestController
@RequestMapping("/aucy")
public class MapController {
    /**
     * 地图service
     */
    private IMapService mapService;

    /**
     * 摄像头service
     */
    private ICameraService cameraService;

    /**
     * 注入
     *
     * @param mapService mapService
     */
    @Autowired
    public void setMapService(IMapService mapService) {
        this.mapService = mapService;
    }

    /**
     * 注入
     *
     * @param cameraService cameraService
     */
    @Autowired
    public void setCameraService(ICameraService cameraService) {
        this.cameraService = cameraService;
    }

    /**
     * 查询摄像头列表
     *
     * @return 摄像头列表
     */
    @RequestMapping(value = "/queryCameraList", method = RequestMethod.GET)
    public CommonVO<List<CameraVO>> queryCameraList() {
        CommonVO<List<CameraVO>> result = new CommonVO<>();
        result.setData(cameraService.queryCameraList());
        return result;
    }

    /**
     * 查询货车信息
     *
     * @param queryParam 入参
     * @return 货车信息
     * @throws InvalidParamException            参数异常
     * @throws DatabaseOperationFailedException 数据库异常
     */
    @RequestMapping("/queryTruckInfo")
    public CommonVO<TruckInfoVO> queryTruckInfo(@RequestBody Map<String, String> queryParam)
            throws InvalidParamException, DatabaseOperationFailedException {
        CheckParamUtil.checkNullRequiredParam(queryParam, queryParam.get("tagId"));
        CommonVO<TruckInfoVO> result = new CommonVO<>();
        result.setData(mapService.queryTruckInfo(queryParam.get("tagId")));
        return result;
    }

    /**
     * 查询货车历史轨迹
     *
     * @param queryParam 入参
     * @return 历史轨迹
     * @throws InvalidParamException            参数异常
     * @throws DatabaseOperationFailedException 数据库异常
     */
    @RequestMapping("/queryTruckTrail")
    public CommonVO<TruckTrailVO> queryTruckTrail(@RequestBody Map<String, String> queryParam)
            throws InvalidParamException, DatabaseOperationFailedException {
        CheckParamUtil.checkNullRequiredParam(queryParam, queryParam.get("tagId"), queryParam.get("truckId"));
        CommonVO<TruckTrailVO> result = new CommonVO<>();
        result.setData(mapService.queryTruckTrail(queryParam.get("tagId"), Integer.valueOf(queryParam.get("truckId"))));
        return result;
    }

    /**
     * 查询货车信息
     *
     * @param queryParam 入参
     * @return 货车信息
     * @throws InvalidParamException            参数异常
     * @throws DatabaseOperationFailedException 数据库异常
     */
    @RequestMapping("/queryVehicleInfo")
    public CommonVO<VehicleInfoVO> queryVehicleInfo(@RequestBody Map<String, String> queryParam)
            throws InvalidParamException, DatabaseOperationFailedException {
        CheckParamUtil.checkNullRequiredParam(queryParam, queryParam.get("tagId"));
        return new CommonVO<>(mapService.queryVehicleInfo(queryParam.get("tagId"), queryParam.get("position")));
    }
}
